Ext.define('Era.view.FinishScreen',{
    extend: 'Ext.container.Container',
    alias: 'widget.finishscreen',
    layout: 'hbox',
    
    initComponent: function() {
        console.log(this.record);
        this.items = [
            {
                xtype: 'previewscreen',
                record: this.record
            },
            {
                xtype: 'button',
                text: 'Finish Event',
                tooltip: 'Display a list of options to finish this event.',
                handler: function() {
                    
                    //get record
                    var record = this.up('finishscreen').record;
                    
                    // add record to history
                    //Era.controller.Main.getStore('history').add(record);

                    // delete the record from the active events
                    Era.controller.Main.getStore('events').remove(record);
                    
                    // create a grid with all events
                    var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore('events')});

                    // load grid in the menu panel
                    Era.controller.Main.showMenuScreen(screen);
                }
            },        
            {
                xtype: 'button',
                text: 'Edit Event',
                tooltip: 'Reschedule or change this event entirely.',
                handler: function() {
 
                    //get record
                    var record = this.up('finishscreen').record;
                    
                    // create edit form
                    var screen = Ext.create('Era.view.EventScreen',{record: record});

                    // load form in the menu panel
                    Era.controller.Main.showMenuScreen(screen);
                }
            },
            {
                xtype: 'button',
                text: 'Delete Event',
                tooltip: 'Delete this event, all related data will be lost.',
                handler: function() {
                    
                    //get record
                    var record = this.up('finishscreen').record;

                    // delete the record from the database
                    Era.controller.Main.getStore('events').remove(record);

                    // create a grid with all events
                    var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore('events')});

                    // load grid in the menu panel
                    Era.controller.Main.showMenuScreen(screen);
                }
            },
            {
                xtype: 'button',
                text: 'Cancel',
                tooltip: 'Return to previous menu.',
                handler: function() {

                    // create a grid with all events
                    var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore('events')});

                    // load grid in the menu panel
                    Era.controller.Main.showMenuScreen(screen);
                }
            },
        ]
        
        this.callParent(this);
    }
});